//
//  Food.m
//  SVN_Tuan_Thuy
//
//  Created by admin on 4/21/15.
//  Copyright (c) 2015 Module4. All rights reserved.
//

#import "Food.h"

@implementation Food
- (instancetype)initWithDictionary:(NSDictionary *)dic {
    self.foodID = [dic objectForKey:@"recipe_id"];
    self.foodF2FUrl = [dic objectForKey:@"f2f_url"];
    self.foodImageURL = [dic objectForKey:@"image_url"];
    self.foodPublisher = [dic objectForKey:@"publisher"];
    self.foodSocialRank = [dic objectForKey:@"social_rank"];
    self.foodSourceUrl = [dic objectForKey:@"source_url"];
    self.foodTitle = [dic objectForKey:@"title"];
    //    [self downloadFoodImage:self.foodImageURL withBock:^(UIImage *img, NSError *err) {
    //        self.foodImage = img;
    //    }];
    return self;
}

- (void)downloadFoodImage:(NSString *)imgUrlString withBock:(void (^)(UIImage *, NSError *))callback {
    NSURL *imgUrl = [NSURL URLWithString:imgUrlString];
    dispatch_async(dispatch_queue_create("dowloadImage", nil), ^{
        NSData * imgData = [NSData dataWithContentsOfURL:imgUrl];
        UIImage* img = [UIImage imageWithData:imgData];
        callback(img,nil);
    });
}
@end
